package com.neuedu.funlifebbs.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neuedu.funlifebbs.bean.Users;
import com.neuedu.funlifebbs.dao.UsersMapper;
import com.neuedu.funlifebbs.query.UsersQuery;
import com.neuedu.funlifebbs.service.UsersService;

/**
 * 
 * @author lzq
 * @version 2019年8月17日下午2:03:55
 *
 */
@Service
public class UsersServiceImpl implements UsersService{
	
	@Autowired
	UsersMapper usersMapper;
	@Override
	public PageInfo<Users> query(UsersQuery usersQuery) {
		// 要不要分页
		if (usersQuery.isPaging()) {
			// 使用分页插件
			PageHelper.startPage(usersQuery.getPageNum(),
					usersQuery.getLimit());
			Page<Users> pageInfo = (Page<Users>) usersMapper
					.query(usersQuery);
			return pageInfo.toPageInfo();
		} else {
			PageInfo<Users> pageInfo = new PageInfo<Users>(
					usersMapper.query(usersQuery));
			return pageInfo;
		}
	}

	@Override
	public int update(Users users) {
		return usersMapper.update(users);
	}

	@Override
	public Users findById(int id) {
		return usersMapper.findById(id);
	}

	@Override
	public Users login(String name, String password) {
		return usersMapper.login(name, password);
	}

	@Override
	public int register(Users users) {
		// TODO Auto-generated method stub
		return usersMapper.register(users);

	}



}
